package com.zhuang.chapter17.work01;

public class Order {
	private String orderID;
	private OrderItem[] items;
	private double total;

	public Order(String orderID) {
		this.orderID = orderID;
		this.items = new OrderItem[3];
	}

	public String getOid() {
		return orderID;
	}

	public void setOid(String orderID) {
		this.orderID = orderID;
	}

	public OrderItem[] getItems() {
		return items;
	}

	public void setItems(OrderItem item, int idx) {
		this.items[idx] = item;
	}

	public double getTotal() {
		calcTotal();
		return total;
	}

	private void calcTotal() {
		double total = 0;
		for (int i = 0; i < items.length; ++i) {
			total += items[i].getNums() * items[i].getBook().getPrice();
		}
		this.total = total;
	}

	public void setTotal(double total) {
		this.total = total;
	}

}
